package cn.cocho.custom.yunCashierDf.common.service;

import cn.cocho.custom.yunCashierDf.common.domain.AreaInfo;
import cn.cocho.custom.yunCashierDf.common.domain.CodelistInfo;
import cn.cocho.dborm.core.Dborm;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WQJ on 2015/11/9.
 */
@Service("commonService")
public class CommonService {

    public List<CodelistInfo> getCodeListInfo(String type_id) {
        String sql = "SELECT * FROM codelist_info WHERE code_type_id = '"+type_id+"' ORDER BY code_id + 1 ASC";
        return Dborm.getEntities(sql, null, CodelistInfo.class);
    }

    public List<CodelistInfo> getCodeListInfo(String type_id,String codevalue) {
        String sql = "SELECT * FROM codelist_info WHERE code_type_id = '"+type_id+"' AND codevalue in "+codevalue+" ORDER BY code_id + 1 ASC";
        return Dborm.getEntities(sql, null, CodelistInfo.class);
    }

    public List<AreaInfo> getAreaProvince() {
        String sql = "SELECT * FROM area_info WHERE level = '1' ORDER BY areaid ASC";
        return Dborm.getEntities(sql, null, AreaInfo.class);
    }

    public List<AreaInfo> getAreaCity(String province) {
        String sql = "SELECT * FROM area_info WHERE level = '2' AND parentid = '"+province+"' ORDER BY areaid ASC";
        return Dborm.getEntities(sql, null, AreaInfo.class);
    }

    public List<AreaInfo> getAreaCounty(String city) {
        String sql = "SELECT * FROM area_info WHERE level = '3' AND parentid = '"+city+"' ORDER BY areaid ASC";
        return Dborm.getEntities(sql, null, AreaInfo.class);
    }
}
